<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // var arr =[1,2,3,4];
        // var res=arr.reduce(function(pre,current,index){
        //     console.log(pre,current,index);
        //     return pre+current;
        // },0)
        // console.log(res);


        // pre 是上次的累加结果 current 是当前循环的值 index 索引
        var arr=[1,2,3,2,3,4,4,8,8,5,5]

        var res=arr.reduce(function(pre,current){
            pre.indexOf(current)===-1 ? pre.push(current) : null;
            return pre;
        },[])
        console.log(res);
    </script>
</body>
</html>